package huawei;

/**
 * 疫情扩散时间
 */
public class Q86 {

    public static void main(String[] args) {
//        int[][] aa = {{1,0,1}, {0,0,0}, {1,0,1}};
//        int[][] aa = {{0,0,0}, {0,0,0}, {0,0,0}};
//        int[][] aa = {{1,1,1}, {1,0,1}, {1,1,0}};

        int[][] aa = {{1,0,0,0}, {0,0,0,0},{0,0,0,0}, {1,0,0,0}};

        int n = 0; // 第几天

        int[][] direction = {{-1, 0},{1, 0},{0, -1}, {0, 1}};

        int target = 1;
        boolean is = false;
        while (true) {
            for (int i = 0; i < aa.length; i++) {
                for (int j = 0; j < aa[i].length; j++) {
                    if (aa[i][j] == target) {
                        for(int[] d : direction) {
                            int x = i + d[0];
                            int y = j + d[1];

                            if (x >= 0 && y >= 0 && x < aa.length && y < aa[i].length && aa[x][y] == 0) {
                                aa[x][y] = target + 1;
                                is = true;
                            }
                        }
                    }
                }
            }
            // 表示这一圈有感染
            if (is) {
                target += 1;
            } else {
                break;
            }

            is = false;
        }

        if (target > 1) {
            System.out.println(target - 1);
        } else {
            System.out.println(-1);
        }
    }
}
